<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width">
        <link rel="shortcut icon" href="../favicon.ico">
        <script src="js/jquery.min.js"></script>
        <title>jsPlumb Community Edition Documentation</title>
        <link href="//fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">




        <link rel="stylesheet" href="css/docs.css">
        <script src="js/docs.js"></script>
    </head>

    <body class="jtk-bootstrap-wide">

        <div class="jtk-header">
    <a class="jtk-logo" href="/"><img src="logo-medium-jsplumb.png"></a>

</div>


        <div class="padding-top" style="margin-top:20px;display:flex;">

                <div id="docs-nav" tabindex="0">
                    <ul>
<li>Imports and Setup

<ul>
<li><a href="home.html#browser">Browser Compatibility</a></li>
<li><a href="home.html#setup">Setup</a></li>
<li><a href="home.html#doctype">Doctype</a></li>
<li><a href="home.html#imports">Required Imports</a></li>
<li><a href="home.html#initializing">Initializing jsPlumb</a></li>
<li><a href="home.html#multiple">Multiple jsPlumb Instances</a></li>
<li><a href="home.html#zindex">Z-Index Considerations</a></li>
<li><a href="home.html#container">Where does jsPlumb add elements?</a></li>
<li><a href="home.html#performance">Performance</a></li>
<li><a href="zooming.html">Zooming</a></li>
<li><a href="defaults.html">Configuring Defaults</a></li>
</ul></li>
<li>Concepts

<ul>
<li><a href="basic-concepts.html">Introduction</a></li>
<li><a href="anchors.html">Anchors</a></li>
<li><a href="connectors.html">Connectors</a></li>
<li><a href="endpoints.html">Endpoints</a></li>
<li><a href="overlays.html">Overlays</a></li>
<li><a href="groups.html">Groups</a></li>
<li><a href="lists.html">Scrollable Lists</a></li>
</ul></li>
<li>Nodes

<ul>
<li><a href="dragging.html">Element Dragging</a></li>
</ul></li>
<li>Connections

<ul>
<li><a href="connections.html">Overview</a></li>
<li><a href="connections.html#programmatic">Programmatic Connections</a></li>
<li><a href="connections.html#common">Reusing Common Settings</a></li>
<li><a href="connections.html#detaching">Detaching Programmatic Connections</a></li>
<li><a href="connections.html#draganddrop">Drag and Drop Connections</a></li>
<li><a href="connections.html#sourcesandtargets">Elements as sources &amp; targets</a></li>
<li><a href="connections.html#maketarget">Element Targets</a></li>
<li><a href="connections.html#makesource">Element Sources</a></li>
<li><a href="connections.html#sourcefilter">Specifying drag source area</a></li>
<li><a href="removing.html">Removing Connections/Endpoints</a></li>
<li><a href="parameters.html">Connection &amp; Endpoint Parameters</a></li>
</ul></li>
<li>Connection &amp; Endpoint Types

<ul>
<li><a href="types.html">Introduction</a></li>
<li><a href="types.html#connection-type">Connection Types</a></li>
<li><a href="types.html#endpoint-type">Endpoint Types</a></li>
</ul></li>
<li>Events

<ul>
<li><a href="events.html">Overview</a></li>
<li><a href="interceptors.html">Interceptors</a></li>
</ul></li>
<li>Appearance

<ul>
<li><a href="paint-styles.html">Styling via Paint Styles</a></li>
<li><a href="styling-via-css.html">Styling via CSS</a></li>
</ul></li>
<li>Querying jsPlumb

<ul>
<li><a href="querying.html#select">Selecting a list of Connections</a></li>
<li><a href="querying.html#selectEndpoints">Selecting a list of Endpoints</a></li>
</ul></li>
<li>Miscellaneous

<ul>
<li><a href="animation.html">Animation</a></li>
<li><a href="utilities.html">Utility Functions</a></li>
</ul></li>
<li>Bundling jsPlumb

<ul>
<li><a href="webpack.html">Webpack</a></li>
</ul></li>
<li>Examples

<ul>
<li><a href="connect-examples.html">jsPlumb.connect</a></li>
<li><a href="draggable-connections-examples.html">Draggable Connections</a></li>
<li><a href="miscellaneous-examples.html">Miscellaneous</a></li>
</ul></li>
<li>Development

<ul>
<li><a href="changelog.html">Changelog</a></li>
<li><a href="development.html">Which files are which?</a></li>
<li><a href="Build.html">Building jsPlumb</a></li>
<li><a href="development-documentation.html">Documentation while developing</a></li>
</ul></li>
</ul>


                </div>

            <div id="docs">
                
                <div class="markdown-body">
                    <h3>Webpack</h3>

<p>jsPlumb can be bundled with Webpack - see <code>/demo/webpack</code> for an example. This page discusses that demonstration.</p>

<h4>package.json</h4>
<div class="highlight"><pre><code class="language-text" data-lang="text">{
  &quot;name&quot;: &quot;jsplumb-webpack-demo&quot;,
  &quot;version&quot;: &quot;1.0.0&quot;,
  &quot;description&quot;: &quot;example of using webpack to bundle jsplumb&quot;,
  &quot;main&quot;: &quot;index.js&quot;,
  &quot;scripts&quot;: {
    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;
  },
  &quot;author&quot;: &quot;jsPlumb &lt;hello@jsplumbtoolkit.com&gt; (https://jsplumbtoolkit.com)&quot;,
  &quot;license&quot;: &quot;MIT&quot;,
  &quot;devDependencies&quot;: {
    &quot;grunt-webpack&quot;: &quot;^1.0.11&quot;,
    &quot;jsplumb&quot;: &quot;file:../../jsplumb.tgz&quot;,
    &quot;webpack&quot;: &quot;^1.13.1&quot;,
    &quot;webpack-dev-server&quot;: &quot;^1.14.1&quot;
  }
}
</code></pre></div>
<p>Note that we reference jsPlumb as a local fie (<code>jsplumb.tgz</code> is the output of <code>npm pack</code>, which creates a local copy of
what <code>npm publish</code> would post to npm). You can just require jsPlumb as you would any other dependency:</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">&quot;devDependencies&quot;:{
  &quot;jsplumb&quot;:&quot;2.2.11&quot;
}
</code></pre></div>
<p>2.2.11 is the most current at the time of writing. It may not be now.</p>

<h4>webpack.config.js</h4>
<div class="highlight"><pre><code class="language-text" data-lang="text">var path = require(&quot;path&quot;);
var webpack = require(&quot;webpack&quot;);
module.exports = {
    cache: true,
    entry: {
        bundle: &quot;./index.js&quot;
    },
    output: {
        path: path.join(__dirname, &quot;dist&quot;),
        publicPath: &quot;dist/&quot;,
        filename: &quot;[name].js&quot;,
        chunkFilename: &quot;[chunkhash].js&quot;
    }
};
</code></pre></div>
<h4>Gruntfile.js</h4>

<p>We&#39;re using Grunt for this demo. You don&#39;t have to use Grunt.</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">module.exports = function(grunt) {

    var webpackConfig = require(&quot;./webpack.config.js&quot;);

    grunt.loadNpmTasks(&quot;grunt-webpack&quot;);

    grunt.initConfig({
        webpack: {
            options: webpackConfig,
            build: {}
        }
    });

    grunt.registerTask(&quot;build&quot;, [&quot;webpack:build&quot;]);
};
</code></pre></div>
<h4>index.js</h4>
<div class="highlight"><pre><code class="language-text" data-lang="text">var j = require(&quot;./node_modules/jsplumb/dist/js/jsplumb.js&quot;).jsPlumb.getInstance({
    Connector: &quot;Flowchart&quot;,
    Anchor: &quot;Bottom&quot;,
    Endpoint: [ &quot;Dot&quot;, { radius: 2 }],
    ConnectionOverlays: [
        [ &quot;Arrow&quot;, { location: 0, width: 10, length: 7, foldbackPoint: 0.62, direction:-1 }]
    ]
});

j.connect({source: &quot;one&quot;, target: &quot;two&quot; });

j.on(window, &quot;resize&quot;, j.repaintEverything);
</code></pre></div>
<p>A point to note is that jsPlumb exports a bunch of things, so the <code>require</code> statement has to further specify <code>jsPlumb</code>
before it can call <code>getInstance</code>. We do this (export a bunch of things) because several of the modules that jsPlumb
depends on can be used independently of jsPlumb.</p>

<p>The full list of exports from the <code>require</code> statement above is:</p>

<ul>
<li>Biltong  - Geometry functions</li>
<li>Katavorio - Drag/drop manager</li>
<li>Mottle    - Event manager</li>
<li>jsBezier  - Bezier curve functions</li>
<li>jsPlumb<br></li>
<li>jsPlumbUtil - Utility functions</li>
</ul>

                </div>
            </div>
        </div>

        <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-49979015-1', 'auto');
    ga('send', 'pageview');

</script>


    </body>

</html>
